<template>
  <tr>
    <td>
      <input type="number" v-model.number="count" @change="emit" />
    </td>
    <td>
      <span>{{ obj["goodsName"] }}</span>
    </td>
    <td>
      <span v-show="obj['count'] === 0">卖光了!!!</span>
    </td>
  </tr>
</template>

<script>
export default {
  // 传入对象有风险, 但是如果是一对一关系可以传入对象-直接修改对象里的值影响外部效果
  props: ["obj", "index"],
  data() {
    return {
      count: 0,
    };
  },
  methods: {
    emit() {
      if (this.count < 0) {
        this.count = 0;
        return;
      } else this.$emit("change-count-event", this.index, this.count);
    },
  },
};
</script>
